import { _decorator, Component, Node, Vec2 } from 'cc';
import { PlayerState } from './PlayerState';
import { StateDefine } from '../../Config';
const { ccclass, property } = _decorator;

@ccclass('PlayerCatchSwordState')
export class PlayerCatchSwordState extends PlayerState {
    onEnter() {
        super.onEnter();
        if(this.player.node.worldPosition.x < this.player.sword.worldPosition.x && this.player.facingDir == -1){
            this.player.Flip()
        }else if(this.player.node.worldPosition.x > this.player.sword.worldPosition.x && this.player.facingDir == 1){
            this.player.Flip()
        }
        this.rb.linearVelocity = new Vec2(this.player.SwordReturnForce*-this.player.facingDir,this.rb.linearVelocity.y);
    }
    onExit() {
        super.onExit()
    }
    update(deltaTime: number) {
        super.update(deltaTime);
        // this.player.ZeroVelocity();
        if (this.triggerCalled)
            this.player.stateMgr.transit(StateDefine.Idle);
    }
    onDestory() { }

    canTransit(to: StateDefine): boolean {
        return true
    }
}


